package wnhz.com.business.groupshop.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseActivity;
import wnhz.com.business.impl.ActionBarClickListener;
import wnhz.com.business.view.TranslucentActionBar;

/**
 * 店铺界面
 */
public class StoreActivity extends BaseActivity implements View.OnClickListener,ActionBarClickListener {

    @BindView(R.id.ll_store)
    LinearLayout llStore;
    @BindView(R.id.tv_call)
    TextView tvCall;
    @BindView(R.id.tv_fansi)
    TextView tvFansi;
    @BindView(R.id.tv_allnumber)
    TextView tvAllnumber;
    @BindView(R.id.tv_paixu)
    TextView tvPaixu;
    @BindView(R.id.recycler_storedata)
    RelativeLayout recyclerStoredata;
    @BindView(R.id.actionbar)
    TranslucentActionBar actionbar;
    private String Title = "";
    private String Status = "";
    private PopupWindow pop ;
    private LinearLayout ll_boss,ll_1,ll_2,ll_3,ll_4,ll_5;
    private TextView tv_1,tv_2,tv_3,tv_4,tv_5;
    private ImageView img_1,img_2,img_3,img_4,img_5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_store);
        ButterKnife.bind(this);
        initview();
        actionbar.setData("李涛的店铺", R.drawable.ic_lefft_white, null, R.drawable.ic_dianpu_guanzhu, "已关注", 0, this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            actionbar.setStatusBarHeight(getStatusBarHeight());
        }
    }

    public static Intent createIntent(Context context) {
        Intent intent = new Intent(context, StoreActivity.class);
        return intent;
    }

    private void initview() {

    }


    @OnClick({R.id.ll_store, R.id.tv_call, R.id.tv_paixu, R.id.iv_actionbar_left})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //商家中心
            case R.id.ll_store:
                startActivity(MerchatCenterActivity.createIntent(this));
                break;
            case R.id.tv_call://客服
                break;
            case R.id.tv_paixu://商品排序
                makepop();
                break;
            case R.id.iv_actionbar_left://回退
                finish();
                break;
        }
    }


    @Override
    public void onLeftClick() {
        finish();
    }

    @Override
    public void onRightClick() {

    }

    @Override
    public void onEditTextClick() {

    }

    //排序pop
    private void makepop()
    {
        View contentView = LayoutInflater.from(this).inflate(R.layout.item_pop_paixu, null);
        pop = new PopupWindow(contentView);
        pop.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        pop.setHeight(WindowManager.LayoutParams.MATCH_PARENT);
        pop.showAsDropDown(actionbar,0,0, Gravity.NO_GRAVITY);
        pop.setOutsideTouchable(true);
        ll_boss = (LinearLayout)contentView.findViewById(R.id.ll_boss);
        ll_1 = (LinearLayout)contentView.findViewById(R.id.ll_1);
        ll_2 = (LinearLayout)contentView.findViewById(R.id.ll_2);
        ll_3 = (LinearLayout)contentView.findViewById(R.id.ll_3);
        ll_4 = (LinearLayout)contentView.findViewById(R.id.ll_4);
        ll_5 = (LinearLayout)contentView.findViewById(R.id.ll_5);
        ll_1.setOnClickListener(this);
        ll_2.setOnClickListener(this);
        ll_3.setOnClickListener(this);
        ll_4.setOnClickListener(this);
        ll_5.setOnClickListener(this);
        ll_boss.setOnClickListener(this);

        tv_1 = (TextView)contentView.findViewById(R.id.tv_1);
        tv_2 = (TextView)contentView.findViewById(R.id.tv_2);
        tv_3 = (TextView)contentView.findViewById(R.id.tv_3);
        tv_4 = (TextView)contentView.findViewById(R.id.tv_4);
        tv_5 = (TextView)contentView.findViewById(R.id.tv_5);

        img_1 = (ImageView) contentView.findViewById(R.id.img_1);
        img_2 = (ImageView) contentView.findViewById(R.id.img_2);
        img_3 = (ImageView) contentView.findViewById(R.id.img_3);
        img_4 = (ImageView) contentView.findViewById(R.id.img_4);
        img_5 = (ImageView) contentView.findViewById(R.id.img_5);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ll_boss:
                pop.dismiss();
                break;
            case R.id.ll_1:
                tv_1.setTextColor(getResources().getColor(R.color.red255));
                tv_2.setTextColor(getResources().getColor(R.color.text51));
                tv_3.setTextColor(getResources().getColor(R.color.text51));
                tv_4.setTextColor(getResources().getColor(R.color.text51));
                tv_5.setTextColor(getResources().getColor(R.color.text51));
                img_1.setVisibility(View.VISIBLE);
                img_2.setVisibility(View.GONE);
                img_3.setVisibility(View.GONE);
                img_4.setVisibility(View.GONE);
                img_5.setVisibility(View.GONE);
                tvPaixu.setText(tv_1.getText().toString());
                pop.dismiss();
                break;
            case R.id.ll_2:
                tv_1.setTextColor(getResources().getColor(R.color.text51));
                tv_2.setTextColor(getResources().getColor(R.color.red255));
                tv_3.setTextColor(getResources().getColor(R.color.text51));
                tv_4.setTextColor(getResources().getColor(R.color.text51));
                tv_5.setTextColor(getResources().getColor(R.color.text51));
                img_1.setVisibility(View.GONE);
                img_2.setVisibility(View.VISIBLE);
                img_3.setVisibility(View.GONE);
                img_4.setVisibility(View.GONE);
                img_5.setVisibility(View.GONE);
                tvPaixu.setText(tv_2.getText().toString());
                pop.dismiss();
                break;
            case R.id.ll_3:
                tv_1.setTextColor(getResources().getColor(R.color.text51));
                tv_2.setTextColor(getResources().getColor(R.color.text51));
                tv_3.setTextColor(getResources().getColor(R.color.red255));
                tv_4.setTextColor(getResources().getColor(R.color.text51));
                tv_5.setTextColor(getResources().getColor(R.color.text51));
                img_1.setVisibility(View.GONE);
                img_2.setVisibility(View.GONE);
                img_3.setVisibility(View.VISIBLE);
                img_4.setVisibility(View.GONE);
                img_5.setVisibility(View.GONE);
                tvPaixu.setText(tv_3.getText().toString());
//                pop.dismiss();
                break;
            case R.id.ll_4:
                tv_1.setTextColor(getResources().getColor(R.color.text51));
                tv_2.setTextColor(getResources().getColor(R.color.text51));
                tv_3.setTextColor(getResources().getColor(R.color.text51));
                tv_4.setTextColor(getResources().getColor(R.color.red255));
                tv_5.setTextColor(getResources().getColor(R.color.text51));
                img_1.setVisibility(View.GONE);
                img_2.setVisibility(View.GONE);
                img_3.setVisibility(View.GONE);
                img_4.setVisibility(View.VISIBLE);
                img_5.setVisibility(View.GONE);
                tvPaixu.setText(tv_4.getText().toString());
                pop.dismiss();
                break;
            case R.id.ll_5:
                tv_1.setTextColor(getResources().getColor(R.color.text51));
                tv_2.setTextColor(getResources().getColor(R.color.text51));
                tv_3.setTextColor(getResources().getColor(R.color.text51));
                tv_4.setTextColor(getResources().getColor(R.color.text51));
                tv_5.setTextColor(getResources().getColor(R.color.red255));
                img_1.setVisibility(View.GONE);
                img_2.setVisibility(View.GONE);
                img_3.setVisibility(View.GONE);
                img_4.setVisibility(View.GONE);
                img_5.setVisibility(View.VISIBLE);
                tvPaixu.setText(tv_5.getText().toString());
                pop.dismiss();
                break;
        }
    }
}
